package com.teradata.tool.xls.read;

import com.teradata.tool.db.DBConnectionPool;

public class Xls2Do {

	public static void main(String[] args) {
		String filename = "G:/Learning/try/test.xlsx";
		String tableName = "this_temp";
		xls2Database(filename, tableName);

		// filename = "E:/test.xlsx";
		// xlsxTable = "major_temp";
		// xls2Database(filename, hxlsTable, xlsxTable);

		// xls2Print(filename);
	}

	// excel->databse
	public static void xls2Database(String filename, String tableName) {

		String fileType = filename.substring(filename.lastIndexOf(".") + 1).toLowerCase();
		try {
			if (fileType.equals("xls")) {
				HxlsBig xls2csv = new HxlsBig(filename, tableName);
				xls2csv.process();
				// null -> conn
				DBConnectionPool.getInstance().closeConnection(null);
			} else if (fileType.equals("xlsx")) {
				XxlsBig howto = new XxlsBig(tableName);
				howto.setCreate(true);
				howto.processOneSheet("F:/new.xlsx", 1);
				howto.process(filename);
				// null -> conn
				DBConnectionPool.getInstance().closeConnection(null);
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
	}

	// excel->print
	public static void xls2Print(String filename) {
		String fileType = filename.substring(filename.lastIndexOf(".") + 1).toLowerCase();
		try {
			if (fileType.equals("xls")) {
				HxlsPrint xls2csv;
				xls2csv = new HxlsPrint(filename);
				xls2csv.process();
			} else if (fileType.equals("xlsx")) {
				XxlsPrint howto = new XxlsPrint();
				howto.setTitleRow(0);
				howto.process(filename);
			}
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println(e.getMessage());
		}
	}
}
